<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="com.tpix.PixieCore" %>
<%@ page import="java.util.*" %>
	
<%
	String url = (String) request.getAttribute("url");
	System.out.println("in edit.jsp url is" + url);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<!-- Get references to Java objects -->
	<%  PixieCore core = (PixieCore) request.getSession().getAttribute("core");
		if (core == null) {
			core = new PixieCore();
			request.getSession().setAttribute("core", core);
		}
		// name of currently selected album
		String currentAlbum = core.getAlbum();
		// for getting list of all user's albums
		ArrayList<String> albums = core.getAlbums();
		Iterator<String> albumItr = albums.iterator();
		%>
		
	<%-- Detect User Logged In --%>
	<%  if (!core.loggedIn()) {
			// user is not logged in. Redirect to login page
			response.sendRedirect("/login.jsp");
		} %>

	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Pixie - Edit</title>
	
	<link type="text/css" rel="stylesheet" href="/stylesheets/edit_photo.css" />
	<link type="text/css" rel="stylesheet" href="/stylesheets/960.css" />
	
	<!-- 	TypeKit -->
	<script type="text/javascript" src="http://use.typekit.com/waa6dbj.js"></script>
	<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
	
</head>

<body>

<div class="container_12">
	<div id="wrapper">
	
	<div class="grid_3 push_1">
		<h3>Add Some Info...</h3><br>
	</div>
	<div class="clear"></div>

	<div class="grid_6 push_1">
		<div class="image_preview">
			<img src='<%=url%>' />
		</div>
	</div>

	<div class="grid_4 push_1">
	<form method="post" action="/saveServlet">
		
			
				<p>
				<strong>Title:</strong><br> <input type="text" name="title" />
				</p>
				<p>
				<strong>Caption:</strong><br> <input type="text" name="caption" />
				</p>
				<p>
				<strong>Description:</strong><br> <input type="text" name="description" />
				</p>
				<p>
				<strong>Album: </strong>
				<select name="album">
				<option value="New Album">New Album</option>
				<% 
				while (albumItr.hasNext()) {
					String selected = "";
					String album = (String) albumItr.next();
					if (album.equals(currentAlbum)) {selected = " selected=\"selected\"";}
					out.println("<option value=\"" + album + "\"" + selected + ">" + album + "</option>");
				}
				%>
				</select>
				</p> 
				<p>
				<strong>New Album:</strong> <br> <input type="text" name="newalbum" />
				</p>
				<p>
				<strong>Tags:</strong><br><textarea rows="5" cols="20" name="tags" ></textarea>
				</p>
		
			<input type="image" value="Save" src="/images/save.png" /> 
			<input type="hidden" name="blob-key" value='<%=request.getAttribute("blob-key")%>' />
		
	</form>
	</div>	
	</div>

</div>
</body>
</html>